<?php
session_start(); 
$id=$_SESSION["user_id"]; 
$time=time(); 
$time_check=$time-600;

include "../common/db.inc";
$mysqli = new mysqli($host, $username, $password,$dbname);
$mysqli->set_charset('utf8');	
if (mysqli_connect_errno()) {
	printf("Connect failed: %s\n", mysqli_connect_error());
	exit();
$mysqli->close();
}
$query = "call sp_DeleteUserOnline('$time_check')";
$result = $mysqli->query($query);
$mysqli->close();

$mysqli = new mysqli($host, $username, $password,$dbname);
$query = "call sp_GetUserOnline('$id')";
$result = $mysqli->query($query);

$count=mysqli_num_rows($result); 

if($count == 0){ 
header('Location: ../common/login.php');
exit();
} 
else { 
$mysqli = new mysqli($host, $username, $password,$dbname);
$query = "call sp_UpdateUserOnline('$id', '$time')";
$result = $mysqli->query($query);
$mysqli->close(); 
}   

?>